/*
 * @Author: fengshan0525 2735332396@qq.com
 * @Date: 2023-03-17 20:43:12
 * @LastEditors: fengshan525 2735332396@qq.com
 * @LastEditTime: 2025-09-21 14:10:56
 * @FilePath: \b-vue3-ts-ele-template\src\api\common\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from '@/api/request'
import { ResponseFormat } from '@/types/http'

export const download = (name: string) => {
  return request.get('/usual/download', {
    params: {
      fileName: name
    },
    responseType: 'blob'
  })
}

export const getRouters = (): Promise<ResponseFormat> => {
  return request.post('/menu/getMenusChildren')
}

/**
 * 创建站点信息
 * @param data
 * @returns
 */
export const createSiteInfo = (data: any): Promise<any> => {
  return request.post('/configuration/createSiteInfo', data)
}

/**
 * 获取站点信息
 * @returns
 */
export const getSiteInfo = (): Promise<any> => {
  return request.get('/configuration/getSiteInfo')
}

/**
 * 更新站点信息
 * @param data
 * @returns
 */
export const updateSiteInfo = (_id: string, data: any) => {
  return request.patch('/configuration/updateSiteInfo/' + _id, data)
}

/**
 * 创建公司信息
 * @param data 公司信息数据，来源于请求体
 * @returns 创建的公司信息
 */
export const createCompanyInfo = (data: any): Promise<any> => {
  return request.post('/configuration/createCompanyInfo', data)
}

/**
 * 获取公司信息
 * @returns 公司信息详情
 */
export const getCompanyInfo = (): Promise<any> => {
  return request.get('/configuration/getCompanyInfo')
}

/**
 * 更新公司信息
 * @param _id 公司信息ID，来源于路径参数
 * @param data 更新的公司信息数据，来源于请求体
 * @returns 更新结果消息
 */
export const updateCompanyInfo = (_id: string, data: any): Promise<any> => {
  return request.patch('/configuration/updateCompanyInfo/' + _id, data)
}

export const getEmailConfig = () => {
  return request.get('/configuration/getAllEmailConfigs')
}

/**
 * 创建邮件收发配置
 * @param data
 * @returns
 */
export const createEmailConfig = (data: any) => {
  return request.post('/configuration/createEmailConfig', data)
}

/**
 * 更新邮件收发配置
 * @param _id
 * @param data
 * @returns
 */
export const updateEmailConfig = (_id: string, data: any) => {
  return request.patch('/configuration/updateEmailConfig/' + _id, data)
}

export const testSendEmail = () => {
  return request.get('/configuration/testSendEmail')
}
